package net.xxcxcxcx.xc_enhancedmob.mixin;

import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.xxcxcxcx.xc_enhancedmob.data.MobData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Entity.class)
public abstract class EntityMixin {
    @Inject(at = @At("HEAD"), method = "onStartedTrackingBy")
    protected void StartedTracking(ServerPlayerEntity player, CallbackInfo ci) {
        if (((Entity) (Object) this) instanceof MobEntity mobEntity) {
            ((MobData) mobEntity).getMobData().forEach((str, component) -> component.onStartedTrackingBy(player));
        }
    }

    @Inject(at = @At("HEAD"), method = "onStoppedTrackingBy")
    protected void StoppedTracking(ServerPlayerEntity player, CallbackInfo ci) {
        if (((Entity) (Object) this) instanceof MobEntity mobEntity) {
            ((MobData) mobEntity).getMobData().forEach((str, component) -> component.onStoppedTrackingBy(player));
        }
    }
}
